<?php
namespace Admin\Controller;
use Admin\Common\CommonController; //使用并继承CommonController类，用作权限的授权
class PageManageController extends CommonController{

	//链接列表
	public function linkListAction(){
		$sql="select * from link";
		$data_m=M();
		$link_res=$data_m->query($sql);
		// var_dump($link_res);
		// exit();
		$this->assign('link_res',$link_res);
		$this->display();
	}

	//添加友情链接
	public function addLinkAction(){
		if(IS_POST){
			$linkname=I('post.linkName');
			$sql="insert into link(linkName) values('$linkname')";
			$data_m=M();
			$link_res=$data_m->execute($sql);
			if($link_res){
				$this->success("添加话题成功",U('Admin/Category/userSuccess'),2);
			}else{
				$this->error("添加话题失败",U('Admin/Category/themeList'),2);
			}
		}else{
			$this->display();
		}		
	}

	//编辑链接
	public function editLinkAction(){
		//当有POST传输数据时
		if(IS_POST){
			// var_dump(I('post.'));
			// exit();
			$linkId=I('post.linkid');
			$linkname=I('post.linkname');
			$sql="update link set linkName='$linkname' where id='$linkId'";
			$data_m=M();
			$result=$data_m->execute($sql);
			// var_dump($result);
			// exit();
			$arr = array('success' =>$result);
			echo json_encode($arr);
			
		}elseif(IS_GET){	
		//当点击编辑时							
			$linkid=I('get.id');
			$sql="select * from link where id='$linkid'";
			$data_m=M();
			$link_res=$data_m->query($sql);
			$link_res=current($link_res);
			// var_dump($link_res);
			// exit();
			$this->assign("link_res",$link_res);
			$this->display();
		}
		
	}


	//友情链接删除
	public function delLinkAction(){
		$linkId=I('POST.linkid');
		$sql="delete from link where id='$linkId'";
		$data_m=M();
		$link_res=$data_m->execute($sql);
		$arr = array('success' =>$link_res);
		echo json_encode($arr);
	}
}
?>